﻿using System;
using UniqueIndex.Model;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;

namespace UniqueIndex
{
    public class Program
    {
        public static void Main()
        {
            // Loading domain configuration section with name "Default".
            var domainConfiguration = DomainConfiguration.Load("Default");
            var domain = Domain.Build(domainConfiguration);

            // Trying to store non-unique values here
            using (var session = domain.OpenSession()) {
                try {
                    using (var t = session.OpenTransaction()) {

                        var book1 = new Book(session) {
                            Title = "Harry Potter and the Philospher's Stone",
                            Isbn = "0747532699"
                        };

                        // By mistake we set the same isbn to the second book
                        var book2 = new Book(session) {
                            Title = "Harry Potter and the Chamber of Secrets",
                            Isbn = "0747532699"
                        };

                        t.Complete();
                    }
                }
                catch (StorageException ex) {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
}
